<template>
  <div class="logistics-info" v-show="isShow">
    <h2>物流相关信息</h2>
    <div class="logistics-info-header">
      <div class="logistics-info-header-left">
        <div
          class="logistics-status"
          :style="{ color: logisticsStatus[0].color }"
        >
          {{ logisticsStatus[0].text }}
        </div>
        <div class="logistics-company">{{ data.logisticsCompany }}</div>
        <div class="logistics-no">{{ data.logisticsNo }}</div>
      </div>
    </div>
    <ul class="logistics-info-list">
      <li v-for="(item, index) in data.logisticsInfo" :key="index">
        <div class="logistics-info-list-time">{{ item.time }}</div>
        <div class="logistics-info-list-content">{{ item.content }}</div>
      </li>
    </ul>
    <button>查看物流详情</button>
  </div>
</template>

<script>
export default {
  props: ["data", "isShow"],
  data() {
    return {
      logisticsStatus: [],
    };
  },
  created() {
    let status = this.data.logisticsStatus;
    switch (status) {
      case 0:
        this.logisticsStatus.push({ text: "未发货", color: "#ccc" });
        break;
      case 1:
        this.logisticsStatus.push({ text: "已发货", color: "#fff222" });
        break;
      case 2:
        this.logisticsStatus.push({ text: "已签收", color: "blue" });
        break;
      case 3:
        this.logisticsStatus.push({ text: "未签收", color: "red" });
        break;
      default:
    }
  },
  directives: {
    color: {
      inserted(el, binding) {
        console.log(el); // 当前元素
        el.style.color = binding.value;
      },
      // 通过 binding.value 可以拿到指令值，指令值修改会 触发 update 函数。
      // 通过 update 钩子，可以监听指令值的变化，进行dom更新操作
      // 触发时机  指令的值发生了变化
      update(el, binding) {
        console.log(el); // 当前元素
        el.style.color = binding.value;
      },
    },
  },
};
</script>

<style socped>
.logistics-info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.logistics-info-header-left {
  display: flex;
  align-items: center;
}
.logistics-status {
  font-weight: bold;
  font-size: 16px;
  color: #007bff;
}

.logistics-company,
.logistics-no {
  margin-left: 10px;
  font-size: 14px;
  color: #333;
}

.logistics-info-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 230px;
  overflow-y: auto;
}

.logistics-info-list li {
  display: flex;
  margin-bottom: 10px;
}

.logistics-info-list-time {
  font-size: 12px;
  color: #999;
  width: 80px;
  text-align: right;
  margin-right: 10px;
}

.logistics-info-list-content {
  font-size: 14px;
  color: #333;
}
</style>